VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmSecUserProfile 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   5460
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   7485
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5460
   ScaleWidth      =   7485
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ITGTab SSTab1 
      Height          =   4845
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   7065
      _ExtentX        =   12462
      _ExtentY        =   8546
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   1
      Tab(0)ContCtrlCap(1)=   "ComunionFrames2"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483630
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   4530
         Left            =   -75000
         TabIndex        =   12
         Top             =   315
         Width           =   7065
         _ExtentX        =   12462
         _ExtentY        =   7990
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   4
         BeginProperty Column00 
            DataField       =   "UserID"
            Caption         =   "User ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "LastName"
            Caption         =   "Last Name"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "FirstName"
            Caption         =   "First Name"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "MI"
            Caption         =   "MI"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   2399.811
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   2429.858
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   615.118
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames2 
         Height          =   4530
         Left            =   0
         Top             =   315
         Width           =   7065
         _ExtentX        =   12462
         _ExtentY        =   7990
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.ComboBox cboUR 
            Height          =   315
            ItemData        =   "frmSecUserProfile.frx":0000
            Left            =   2640
            List            =   "frmSecUserProfile.frx":000A
            Style           =   2  'Dropdown List
            TabIndex        =   14
            Top             =   3600
            Visible         =   0   'False
            Width           =   1395
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   3015
            Top             =   405
         End
         Begin VB.CommandButton cmdPickDept 
            Height          =   300
            Left            =   2910
            Picture         =   "frmSecUserProfile.frx":001B
            Style           =   1  'Graphical
            TabIndex        =   3
            Top             =   2055
            Width           =   345
         End
         Begin VB.CommandButton cmdPickUnitDiv 
            Height          =   300
            Left            =   2910
            Picture         =   "frmSecUserProfile.frx":0165
            Style           =   1  'Graphical
            TabIndex        =   2
            Top             =   2355
            Width           =   345
         End
         Begin ITGControls.ITGTextBox txtUserID 
            Height          =   285
            Left            =   195
            TabIndex        =   4
            Top             =   495
            Width           =   2700
            _ExtentX        =   4551
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "User ID"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1360
         End
         Begin ITGControls.ITGTextBox txtFName 
            Height          =   285
            Left            =   195
            TabIndex        =   5
            Top             =   1305
            Width           =   4080
            _ExtentX        =   6985
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "First Name"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   2740
         End
         Begin ITGControls.ITGTextBox txtMI 
            Height          =   285
            Left            =   195
            TabIndex        =   6
            Top             =   1605
            Width           =   1800
            _ExtentX        =   2963
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Middle Initial"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   460
         End
         Begin ITGControls.ITGTextBox txtLName 
            Height          =   285
            Left            =   195
            TabIndex        =   7
            Top             =   1005
            Width           =   4080
            _ExtentX        =   6985
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Last Name"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   2740
         End
         Begin ITGControls.ITGTextBox txtDeptDesc 
            Height          =   285
            Left            =   3285
            TabIndex        =   8
            Top             =   2070
            Width           =   3570
            _ExtentX        =   6191
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   ""
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3510
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtDeptID 
            Height          =   285
            Left            =   195
            TabIndex        =   9
            Top             =   2070
            Width           =   2700
            _ExtentX        =   4551
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Department"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1360
         End
         Begin ITGControls.ITGTextBox txtUnitDivDesc 
            Height          =   285
            Left            =   3285
            TabIndex        =   10
            Top             =   2370
            Width           =   3570
            _ExtentX        =   6191
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   ""
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3510
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtUnitDiv 
            Height          =   285
            Left            =   195
            TabIndex        =   11
            Top             =   2370
            Width           =   2700
            _ExtentX        =   4551
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Unit Division"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1280
            TextBoxWidth    =   1360
         End
         Begin MSDataGridLib.DataGrid dtgUserRole 
            Height          =   1290
            Left            =   120
            TabIndex        =   13
            Top             =   3000
            Width           =   6705
            _ExtentX        =   11827
            _ExtentY        =   2275
            _Version        =   393216
            AllowUpdate     =   0   'False
            AllowArrows     =   -1  'True
            Appearance      =   0
            HeadLines       =   1
            RowHeight       =   15
            TabAction       =   2
            FormatLocked    =   -1  'True
            BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ColumnCount     =   5
            BeginProperty Column00 
               DataField       =   "cCompanyID"
               Caption         =   "Comp ID"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column01 
               DataField       =   "UserID"
               Caption         =   "User ID"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1124
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column02 
               DataField       =   "RoleID"
               Caption         =   "Role ID"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   ""
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column03 
               DataField       =   "Description"
               Caption         =   "Role Description"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   0
                  Format          =   "#,##0.00"
                  HaveTrueFalseNull=   0
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1033
                  SubFormatType   =   0
               EndProperty
            EndProperty
            BeginProperty Column04 
               DataField       =   "lDefault"
               Caption         =   "Default Role"
               BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
                  Type            =   5
                  Format          =   ""
                  HaveTrueFalseNull=   1
                  TrueValue       =   "True"
                  FalseValue      =   "False"
                  NullValue       =   ""
                  FirstDayOfWeek  =   0
                  FirstWeekOfYear =   0
                  LCID            =   1124
                  SubFormatType   =   7
               EndProperty
            EndProperty
            SplitCount      =   1
            BeginProperty Split0 
               AllowRowSizing  =   0   'False
               BeginProperty Column00 
                  ColumnAllowSizing=   -1  'True
                  Locked          =   -1  'True
                  Object.Visible         =   0   'False
                  ColumnWidth     =   884.976
               EndProperty
               BeginProperty Column01 
                  Locked          =   -1  'True
                  Object.Visible         =   0   'False
               EndProperty
               BeginProperty Column02 
                  Locked          =   -1  'True
                  ColumnWidth     =   1544.882
               EndProperty
               BeginProperty Column03 
                  Locked          =   -1  'True
                  ColumnWidth     =   3764.977
               EndProperty
               BeginProperty Column04 
                  Button          =   -1  'True
                  ColumnWidth     =   1065.26
               EndProperty
            EndProperty
         End
         Begin VB.Line Line1 
            BorderColor     =   &H00808080&
            X1              =   210
            X2              =   6960
            Y1              =   2880
            Y2              =   2880
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   255
      Left            =   0
      TabIndex        =   1
      Top             =   5205
      Width           =   7485
      _ExtentX        =   13203
      _ExtentY        =   450
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmSecUserProfile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables





'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset

'ADO Connection variables
Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection

'Form mode enumeration
Public Enum eSecUPMode
    Normal
    AddNewEdit
    Find
End Enum
Private Mode As eSecUPMode

'Other declaration
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable

Public dtgName As String

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

 
Private Sub cboUR_Click()
    rsDetail!lDefault = cboUR.Text
    vBookMark = rsDetail.Bookmark
End Sub

Private Sub cboUR_LostFocus()
    If Me.ActiveControl.Name <> "cboUR" Then
        cboUR.Visible = False
        
        Dim i As Integer
        GetChild
        
        If (cboUR.Text = "True") Then
            For i = 0 To rsDetail.RecordCount - 1
                If (vBookMark <> rsDetail.Bookmark) Then
                    rsDetail!lDefault = False
                End If
                rsDetail.MoveNext
            Next i
        End If
        
        
    End If
End Sub

Private Sub cmdPickDept_Click()
    If lPickListActive Then Exit Sub
    frmITGPickList.mType = SecDepartment
    frmITGPickList.Show vbModal
    txtDeptID = frmITGPickList.mCode
    txtDeptDesc = frmITGPickList.mName
    If Trim(txtDeptDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickRole_Click()
    If lPickListActive Then Exit Sub
    frmITGPickList.mType = SecRole
    frmITGPickList.Show vbModal
    'txtRoleID = frmITGPickList.mCode
    'txtRoleDesc = frmITGPickList.mName
    'If Trim(txtRoleDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickUnitDiv_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtUnitDiv)
    frmITGPicker.zType = QProfitCenter
    frmITGPicker.Show vbModal
    txtUnitDiv = frmITGPicker.zCode
    txtUnitDivDesc = frmITGPicker.zName
    If Trim(txtUnitDivDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgUserRole_ButtonClick(ByVal ColIndex As Integer)
    Select Case ColIndex
        Case 4
            MoveCombo cboUR, dtgUserRole, dtgUserRole.Columns(4)
    End Select
    
End Sub

Private Sub dtgUserRole_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgUserRole.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

'Private Sub dtgUserRole_ButtonClick(ByVal ColIndex As Integer)
'    If Mode <> AddNewEdit Then Exit Sub
'    Select Case ColIndex
'        Case 2
'            If lPickListActive Then Exit Sub
'            sFilterString = Trim(rsDetail!cItemNo)
'            frmITGPicker.zType = QUserRole
'            'added condition
'            frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
'
'            frmITGPicker.Show vbModal
'            rsDetail!cRoleID = Trim(frmITGPicker.zCode) & ""
'            rsDetail!cDescription = Trim(frmITGPicker.zName) & ""
'            If (Trim(frmITGPicker.zName) & "") <> "" Then
'                dtgUserRole.Col = 4
'            End If
'    End Select
'End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()

    Set FrmName = Me
    FormSetup
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'SC02'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    Mode = Find
    txtUserID.Locked = False
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    
    
    
    
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing
    
    Set frmSecUserProfile = Nothing

    lCloseWindow = True
'
'    'oForm(Me.Tag).Mode = 1
'    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtUserID.BackColor = &HE0FFFF
    Mode = AddNewEdit
    
    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connDetail
        OpenRecordsetWithCN rsDetail, "*", "SEC_USER_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "SEC_USER", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
    
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    SSTab1.ActiveTab = 0
    txtUserID.SetFocus

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler
    
    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
    Else
        RSZero
        Mode = Find
    End If
    
    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    If rsHeader.Status = adRecNew Then
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler
    
    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True
    
    If Not MandatoryOK Then Exit Sub
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    
    
    If lBoolean Then rsHeader!Password = Encrypt("PASSWORD")
    
    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connDetail.CommitTrans
    connHeader.CommitTrans
    
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
    Mode = Normal
    
    MsgBox "Record/s successfully saved.", vbInformation, "ComUnion"
    sbRS.Panels(2) = ""

    'Audit trail
    UpdateLogFile "Sec - User Profile", Trim(txtUserID), IIf(lBoolean, "Inserted", "Updated")

ErrHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        connDetail.RollbackTrans
        connHeader.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "ComUnion"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "ComUnion"
        connDetail.RollbackTrans
        connHeader.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtUserID.Locked = True
    SSTab1.ActiveTab = 0
    txtLName.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub
    
    If UCase(Trim(txtUserID)) = "SA" Then
        MsgBox "User cannot be deleted. [Administrator ID]", vbCritical, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Sec - User Profile", Trim(txtUserID), "Deleted"
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    rsHeader.Delete adAffectCurrent
    
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtUserID.Locked = True
    frmITGSearch.Show
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
    Dim sTemp As String
        If Mode = Find Then
            
            FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
            OpenNewConnection connHeader
            OpenNewConnection connDetail
            
            Set rsHeader = Nothing
            Set rsDetail = Nothing
            Set rsHeader = New ADODB.Recordset
            Set rsDetail = New ADODB.Recordset
        
            sTemp = Trim$(GetSearchString)
            If sTemp = "ERROR" Then
                MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
                BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
                Exit Sub
            End If
                
            OpenRecordsetWithCN rsHeader, "*", "SEC_USER", connHeader, IIf(sTemp = "", "", "where " & sTemp), True
            OpenRecordsetWithCN rsDetail, "*", "SEC_USER_T", connDetail, IIf(sTemp = "", "", "where " & sTemp) ', True
            
            Set FrmName = Me
            FormLocking True
            
            If rsHeader.RecordCount = 0 Then
                FormWaitHide
                MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
                rsHeader.Close
                BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
                txtUserID.Locked = False
                txtUserID.SetFocus
                Exit Sub
            End If
            
            SetDataSource
            SetDataField
            
            txtUserID.BackColor = &HE0FFFF
            Mode = Normal
            
            BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
        
            FormWaitHide
    Else
    RSZero
    Mode = Find
    End If
End Sub

Private Function GetSearchString() As String
    On Error GoTo ErrorHandler
    Dim sWhere As String

    GetSearchString = True
    
    If Trim$(txtUserID.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " UserID LIKE '" & Trim$(txtUserID.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
End Sub

'Move previous
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
On Error GoTo ErrorHandler
    If rsHeader!UserID = "" Then Exit Sub
    
    If dtgName = "dtgUserRole" Then
        If lPickListActive Then Exit Sub
        frmITGPicker.zType = QUserRole
        'added condition
        frmITGPicker.Condition = "where cCompanyID = '" & COID & "'"
        
        frmITGPicker.Show vbModal
        rsDetail.AddNew
        
        rsDetail!cCompanyID = COID
        rsDetail!UserID = Trim(rsHeader!UserID)
        rsDetail!RoleID = Trim(frmITGPicker.zCode) & ""
        rsDetail!Description = Trim(frmITGPicker.zName) & ""
        rsDetail!lDefault = False
        
        dtgUserRole.Col = 0
        
        If (Trim(frmITGPicker.zName) & "") <> "" Then
            dtgUserRole.Col = 4
        End If

        GetChild
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
        dtgUserRole.Col = 0
        dtgUserRole.SetFocus
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number <> 0 Then
        MsgBox err.Description, vbInformation, msgTtl
    End If
End Sub

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "UserID = '" & Trim(rsHeader!UserID) & "'"
End Sub

'Delete line in the detail recordset
'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler
    
    If dtgName = "dtgUserRole" Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgUserRole.Bookmark
        GetChild
        dtgUserRole.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
    End If
    GetChild
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo all
Public Sub TBUndoLineAll()
    'Not available for this module
End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    'Not available for this module
End Sub

'Post current record
Public Sub TBPostRecord()
    'Not available for this module
End Sub

'Cancel current record
Public Sub TBCancelRecord()
    'Not available for this module
End Sub

'Print
Public Sub TBPrintRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgUserRole.DataSource = rsDetail
    
End Sub
    
'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtUserID.DataField = !UserID
        txtLName.DataField = !LastName
        txtFName.DataField = !FirstName
        txtMI.DataField = !MI
        'txtRoleID.DataField = !RoleID
        txtDeptID.DataField = !DeptID
        txtUnitDiv.DataField = !cDivision
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler
    
    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount
        
        If rsHeader.Status <> adRecNew Then
            txtUserID.Locked = True
        Else
            txtUserID.Locked = False
        End If
        
        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
        
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtUserID.Locked = False
    End If
    
ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If
    
End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
    
    If Mode <> Find Then Exit Sub
    If txtUserID.BackColor = &HE0FFFF Then
        txtUserID.BackColor = &HE0E0E0
        Exit Sub
    End If
    If txtUserID.BackColor <> &HE0FFFF Then
        txtUserID.BackColor = &HE0FFFF
        Exit Sub
    End If

End Sub

Private Sub txtDeptID_Change()
    txtDeptDesc = ""
    txtDeptDesc = GetValueFrTable("Description", "SEC_DEPARTMENT", "DeptID = '" & Trim(txtDeptID) & "'", True)
End Sub

Private Sub txtDeptID_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtDeptDesc) = "" And Trim(txtDeptID) <> "" Then cmdPickDept_Click
End Sub

'Private Sub txtRoleID_Change()
'    txtRoleDesc = ""
'    txtRoleDesc = GetValueFrTable("Description", "SEC_ROLE", "RoleID = '" & Trim(txtRoleID) & "'", True)
'End Sub

'Private Sub txtRoleID_LostFocus()
'    If Mode <> AddNewEdit Then Exit Sub
'    If Trim(txtRoleDesc) = "" And Trim(txtRoleID) <> "" Then cmdPickRole_Click
'End Sub

Private Sub txtUnitDiv_Change()
    txtUnitDivDesc = ""
    txtUnitDivDesc = GetValueFrTable("cDescription", "PROFITCENTER", "cPCCode = '" & Trim(txtUnitDiv) & "'")
End Sub

Private Sub txtUnitDiv_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtUnitDivDesc) = "" And Trim(txtUnitDiv) <> "" Then cmdPickUnitDiv_Click
End Sub




Private Sub txtUserID_LostFocus()
    'Does Code Already exists
    If Mode = AddNewEdit Then
        If Trim(txtUserID) = "" Then
            MsgBox "Empty primary input.", vbInformation, "ComUnion"
            txtUserID.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtUserID = Trim(txtUserID)
            If IDExisting(rsHeader, "UserID", "SEC_USER", Trim(rsHeader!UserID), , True) Then
                MsgBox "User ID already exists.", vbInformation, "ComUnion"
                txtUserID.SetFocus
            End If
        End If
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    
    MandatoryOK = True
    
    If Trim(txtUserID) = "" Then
        MandatoryOK = False
        MsgBox "Field 'User ID' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtUserID.SetFocus
        Exit Function
    End If
    
    If rsHeader.Status = adRecNew Then
        If IDExisting(rsHeader, "UserID", "SEC_USER", Trim(rsHeader!UserID), , True) Then
            MandatoryOK = False
            MsgBox "User ID already exists.", vbInformation, "ComUnion"
            txtUserID.SetFocus
            Exit Function
        End If
    End If
    
    If Trim(txtLName) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Last Name' is mandatory. Null value is not allowed", vbInformation, "ComUnion"
        txtLName.SetFocus
        Exit Function
    ElseIf Trim(txtFName) = "" Then
        MandatoryOK = False
        MsgBox "Field 'First Name' is mandatory. Null value is not allowed", vbInformation, "ComUnion"
        txtFName.SetFocus
        Exit Function
    ElseIf Trim(txtMI) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Middle Initial' is mandatory. Null value is not allowed", vbInformation, "ComUnion"
        txtMI.SetFocus
        Exit Function
'    ElseIf Trim(txtRoleID) = "" Then
'        MandatoryOK = False
'        MsgBox "Field 'User Role' is mandatory. Null value is not allowed", vbInformation, "ComUnion"
'        txtRoleID.SetFocus
'        Exit Function
    ElseIf Trim(txtDeptID) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Department' is mandatory. Null value is not allowed", vbInformation, "ComUnion"
        txtDeptID.SetFocus
        Exit Function
    End If

    GetChild
    
    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, msgTtl
        MandatoryOK = False
        Exit Function
    End If

End Function

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    
    Set dtgUserRole.DataSource = Nothing
    dtgUserRole.Refresh
        
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtUserID.Locked = False
    txtUserID.SetFocus
    
    Mode = Find
End Sub









